package com.liuxing.javaSpringBoot.modules.test.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.liuxing.javaSpringBoot.modules.common.entity.AbstractEntity;

import javax.persistence.*;

/**
 * Created by IntelliJ IDEA.
 * @File Card.java
 * @Auth liuxing
 * @Date 2021/8/20 10:00
 * @Email liuxing997@foxmail.com
 */
@Entity
@Table(name = "test_card")
public class Card extends AbstractEntity {
    @Column(length = 50)
    private String cardNumber;

    /**
     * OneToOne：一对一关系中，有外键方使用 JoinColumn 注解，另一方使用 mappedBy 属性（可选）
     * cascade：联级操作
     * fetch：加载数据策略
     * JsonIgnore：不序列化该字段，避免无限递归
     */
    @OneToOne(mappedBy = "studentCard", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JsonIgnore
    private Student student;

    public String getCardNumber() {
        return cardNumber;
    }

    public void setCardNumber(String cardNumber) {
        this.cardNumber = cardNumber;
    }
}
